package com.shop.web;

import com.shop.model.PageParam;
import com.shop.model.dto.Job;
import com.shop.model.vo.Rsp;
import com.shop.service.QrtzJobDetailsService;
import lombok.AllArgsConstructor;
import org.quartz.SchedulerException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : WanS
 * @date : 11:23 2020/11/23
 * 定时任务表
 */
@Validated
@RestController
@AllArgsConstructor
public class JobController {
    /**
     * 服务对象
     */
    private final QrtzJobDetailsService qrtzJobDetailsService;
    /**
     * 查询定时任务列表
     */
    @PostMapping("getJobList")
    public Rsp getJobList(@RequestBody PageParam<Job> pageParam) {
        return Rsp.success(qrtzJobDetailsService.getJobList(pageParam));
    }

    /**
     * 添加定时任务
     */
    @PostMapping("/insert")
    public Rsp insert(@RequestBody Job job) throws SchedulerException, ClassNotFoundException {
         return qrtzJobDetailsService.insert(job);
    }

    /**
     * 修改定时任务
     */
    @PostMapping("/update")
    public Rsp update(@RequestBody Job job) {
        return qrtzJobDetailsService.update(job);
    }

    /**
     * 删除定时任务
     */
    @PostMapping("/delete")
    public Rsp delete(@RequestBody Job job) {
        return qrtzJobDetailsService.delete(job);
    }

   /**
    * 立即执行任务
    */
   @PostMapping("/run")
   public Rsp run(@RequestBody Job job) throws SchedulerException {
       return qrtzJobDetailsService.run(job);
   }

    /**
     * 暂停和执行任务
     */
    @PostMapping("/pauseAndStart")
    public Rsp pauseAndStart(@RequestBody Job job) throws SchedulerException {
        return qrtzJobDetailsService.pauseAndStart(job);
    }
}
